home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
src
/
haeberli
/
libgutil
/
lut.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
3KB
|
100 lines
/*
* Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
* rights reserved under the Copyright Laws of the United States.
*/
/*
* lut -
* Create and apply look up tables.
*
* Paul Haebeli - 1990
*/
#include "lut.h"
float frand();
lut *makelut(func,insteps,outsteps,stoclut)
float (*func)();
int insteps, outsteps, stoclut;
{
lut *l;
int i;
float low, high, inspace;
l = (lut *)mymalloc(sizeof(lut));
l->insteps = insteps;
l->outsteps = outsteps;
l->stoclut = stoclut;
if(stoclut) {
l->flow = (float *)mymalloc(insteps*sizeof(float));
l->fhigh = (float *)mymalloc(insteps*sizeof(float));
l->fdelta = (float *)mymalloc(insteps*sizeof(float));
inspace = insteps-1.0;
for(i=0; i<insteps; i++) {
low = (i-0.499)/inspace;
high = (i+0.499)/inspace;
if(low<0.0) low = 0.0;
if(low>1.0) low = 1.0;
if(high>1.0) high = 1.0;
if(high<0.0) high = 0.0;
if((i==0) || (i == (insteps-1))) {
l->flow[i] = (func)(i/inspace);
l->fhigh[i] = (func)(i/inspace);
} else {
l->flow[i] = (func)(low);
l->fhigh[i] = (func)(high);
}
l->fdelta[i] = l->fhigh[i]-l->flow[i];
}
} else {
l->stab = (unsigned short *)mymalloc(insteps*sizeof(unsigned short));
inspace = insteps-1.0;
for(i=0; i<insteps; i++)
l->stab[i] = (l->outsteps-1)*(func)(i/inspace)+0.5;
}
return l;
}
applylut(l,sptr,n)
lut *l;
unsigned short *sptr;
int n;
{
float val;
float *fdelta, *flow;
unsigned short *stab;
float outspace;
int ival;
if(l->stoclut) {
fdelta = l->fdelta;
flow = l->flow;
outspace = l->outsteps-1;
while(n--) {
val = outspace*(flow[*sptr]+frand()*fdelta[*sptr]);
ival = val;
if((val-ival)<=frand())
*sptr++ = ival;
else
*sptr++ = ival+1;
}
} else {
stab = l->stab;
while(n--) {
*sptr = stab[*sptr];
sptr++;
}
}
}